from flask import Blueprint, current_app, request
from flask_login import current_user

admins_bp = Blueprint(
    'admins',
    __name__,
    url_prefix='/admins',
    template_folder='templates',
    static_folder='static',
    static_url_path='static'
)


@admins_bp.before_request
def admins_before_request():
    # 权限验证
    if request.endpoint not in current_app.config.get('ADMINS_WHITE_ROUTES') and not current_user.is_authenticated:
        return current_app.login_manager.unauthorized()


@admins_bp.context_processor
def template_context():
    is_pjax = True if 'X-PJAX' in request.headers else False
    return dict(is_pjax=is_pjax)


from . import auth, category, article, tag, link, site, picture, welcome
